import { HashRouter as Router, Route, Routes } from "react-router-dom";

import DeviceLists from "../pages/device/deviceLists";
import ProjectAdmin from "../pages/project/projectLists";
import GroupLists from "../pages/group/groupLists";
import TemplateManagement from "../pages/template/templateManagement";
import ProtocolLists from "../pages/protocol/protocolLists";

import ListMonitorLists from "../pages/listMonitor/listMonitorLists";
import Protocol from "../pages/protocol/protocolLists";
import CrontabLists from "../pages/crontab/crontabLists";
import DeviceTest from "../pages/device/test";
import RouterPage from "../pages/routerPage/routerLists";
import AlarmLists from "../pages/alarm/alarmLists";
import LoginPage from "../pages/login/login";
import RegisterGroupLists from "../pages/device/deviceRegisterGroup/registerGroupLists";
import RegisterAdd from "../pages/group/registerAdd";
import React, { useEffect } from "react";
const SelftRouters: React.FC = () => {
  // 检查是否已登录
  const isLoggedIn = () => {
    return localStorage.getItem("token") !== null;
  };

  return (
    <Routes>
      <Route path="/login" element={<LoginPage />} />
      {isLoggedIn() ? (
        <>
          <Route path="/" element={<DeviceLists />} />
          <Route path="/device" element={<DeviceLists />} />
          <Route path="/project" element={<ProjectAdmin />} />
          <Route path="/deviceGroup" element={<GroupLists />} />
          <Route path="/protocol" element={<ProtocolLists />} />
          <Route path="/listMonitor" element={<ListMonitorLists />} />
          <Route path="/protocol" element={<Protocol />} />
          <Route path="/crontab" element={<CrontabLists />} />
          <Route path="/test" element={<DeviceTest />} />
          <Route path="/router" element={<RouterPage />} />
          <Route path="/alarm" element={<AlarmLists />} />
          <Route path="/deviceTemplate" element={<TemplateManagement />} />
          <Route path="/registerGroupLists" element={<RegisterGroupLists />} />
          <Route path="/registerAdd" element={<RegisterAdd />} />
        </>
      ) : (
        <Route path="*" element={<LoginPage />} />
      )}
    </Routes>
  );
};

export default SelftRouters;
